import createAxios from '/@/utils/axios'

// 权限管理相关API
export function getPermissionList(params: object = {}) {
    return createAxios({
        url: 'admin/yxerp.permission/index',
        method: 'get',
        params: params
    })
}

export function addPermission(data: object) {
    return createAxios({
        url: 'admin/yxerp.permission/add',
        method: 'post',
        data: data
    })
}

export function updatePermission(id: number, data: object) {
    return createAxios({
        url: 'admin/yxerp.permission/edit',
        method: 'post',
        params: { ids: id },
        data: data
    })
}

export function deletePermission(id: number) {
    return createAxios({
        url: 'admin/yxerp.permission/del',
        method: 'post',
        params: { ids: id }
    })
}

export function assignPermissionToPosition(positionId: number, permissionIds: number[]) {
    return createAxios({
        url: 'admin/yxerp.permission/assignToPosition',
        method: 'post',
        data: {
            position_id: positionId,
            permission_ids: permissionIds
        }
    })
}

export function assignPermissionToEmployee(employeeId: number, permissionIds: number[]) {
    return createAxios({
        url: 'admin/yxerp.permission/assignToEmployee',
        method: 'post',
        data: {
            employee_id: employeeId,
            permission_ids: permissionIds
        }
    })
}

export function getPositionPermissions(positionId: number) {
    return createAxios({
        url: 'admin/yxerp.permission/getPositionPermissions',
        method: 'get',
        params: { position_id: positionId }
    })
}

export function getEmployeePermissions(employeeId: number) {
    return createAxios({
        url: 'admin/yxerp.permission/getEmployeePermissions',
        method: 'get',
        params: { employee_id: employeeId }
    })
} 

// 获取YXERP插件权限规则
export function getRules(params: any) {
    return createAxios({
      url: '/admin/yxerp.permission/getRules',
      method: 'get',
      params
    })
  }
  
  // 保存用户权限设置
  export function saveUserPermission(data: any) {
    return createAxios({
      url: '/admin/yxerp.permission/saveUserPermission',
      method: 'post',
      data
    })
  }
  
  // 获取数据权限范围
  export function getDataScope(params: any) {
    return createAxios({
      url: '/admin/yxerp.permission/getDataScope',
      method: 'get',
      params
    })
  }
  
  // 检查权限
  export function checkPermission(params: any) {
    return createAxios({
      url: '/admin/yxerp.permission/checkPermission',
      method: 'get',
      params
    })
  }